import { request, urlHead } from "./request";
import { token } from "./token";
import { fetchRequ } from "./fetchRequ";

// 获取所有用户列表
export async function getUsers() {
  return await request.get(
    urlHead + "/data/users.json" + "?timestamp=" + new Date().getTime()
  );
}

// 写入所有用户列表
export async function setUsers(data, methodType = "axios") {
  if (urlHead) {
    // app
    methodType = "fetch";
  }
  // data为请求体 [上传的对象]
  if (methodType === "axios") {
    return await request.put(
      urlHead + "/data/users.json", // "?timestamp=" + new Date().getTime(),
      data
    );
  } else if (methodType === "fetch") {
    // { method, url, data, token };
    return await fetchRequ({
      method: "put",
      url: "/data/users.json", // "?timestamp=" + new Date().getTime(),
      data: data,
      token: token.put.users,
    });
  }
}
